package com.hb.trade.api.push.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import org.fzzn.core.cache.redis.StringRedisService;
import org.springframework.stereotype.Component;

/**
 * @description: 前置机推送 每天活得从1开始的订单号
 * @author: itzsl
 * @create: 2020-03-11 13:11
 */
@Component
public class OrderNumberManager {
    private static final String redisKey = "front_end:processor:";

    protected final StringRedisService redisService;

    public OrderNumberManager(StringRedisService redisService) {
        this.redisService = redisService;
    }

    public  Long getValue(String key) {
        String newKey = redisKey + "_" + key;
        Long id = 100000L;
        String idStr = redisService.get(newKey);
        if (StrUtil.isNotEmpty(idStr)){
            id = Long.valueOf(idStr) + 1;
        }
        redisService.set(newKey,id.toString(),86400000L);

        return Long.valueOf(redisService.get(newKey));
    }

}
